home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex8-9.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  50 lines

  1. // ex8-9.c -- Sorting on Multiple Keys with ArrayOb and KeySortCltn
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-9.c,v 3.0 90/05/15 22:46:30 kgorlen Rel $
  4.  
  5. #include "KeySortCltn.h"
  6. #include "ArrayOb.h"
  7. #include "Assoc.h"
  8. #include "Patient.h"
  9. #include "Integer.h"
  10.  
  11. void sort_Patient(KeySortCltn& c, Patient& p)
  12. {
  13. // Set up ArrayOb with sort keys zip,name,ss_number
  14.     ArrayOb& key = *new ArrayOb(3);
  15.     key[0] = new Integer(p.zip());
  16.     key[1] = new String(p.name());
  17.     key[2] = new String(p.ssn());
  18.     c.addAssoc(key,p);
  19. }
  20.  
  21. main()
  22. {
  23.     KeySortCltn cltn;
  24.  
  25. // Define 6 Patient records 
  26. // in parent/child pairs with the same name and zip
  27. // and sort with ArrayOb key in a KeySortCltn
  28.     sort_Patient(cltn,
  29.         *new Patient("Smith John A.","333-22-1111",22223));
  30.     sort_Patient(cltn,
  31.         *new Patient("Smith John A.","111-22-3333",22223));
  32.     sort_Patient(cltn,
  33.         *new Patient("Fried Harry I.","987-65-4321",22221));
  34.     sort_Patient(cltn,
  35.         *new Patient("Fried Harry I.","123-45-6789",22221));
  36.     sort_Patient(cltn,
  37.         *new Patient("Chavez Maria G.","666-555-4444",22223));
  38.     sort_Patient(cltn,
  39.         *new Patient("Chavez Maria G.","444-555-6666",22223));
  40.  
  41. // Print Patient records in sorted order
  42.     cout << "Sort by zip, name, and ssn: \n\n";
  43.  
  44.     Iterator it(cltn);
  45.     while (it++) {
  46.         Assoc& as = *(Assoc*)it();
  47.         cout << *as.value() << endl;
  48.     }
  49. }
  50.